home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8976 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: rz.uni-karlsruhe.de!not-for-mail
  2. From: hf@colibri.de (Harald Fuchs)
  3. Newsgroups: comp.programming.threads,comp.lang.c++,comp.unix.osf.osf1,comp.unix.programmer,comp.object
  4. Subject: Re: Looking for best design for using pthreads in C++ objects
  5. Date: 27 Feb 1996 19:07:02 +0100
  6. Organization: Colibri GmbH, Germany
  7. Sender: hf@themroc.colibri.de
  8. Message-ID: <puag248wxl.fsf@themroc.colibri.de>
  9. References: <3128ff8b.666031216@news.clark.net> <312A0E5F.7B2C@ix.netcom.com>
  10.     <31320705.41C6@zko.dec.com>
  11. NNTP-Posting-Host: teco10a.teco.uni-karlsruhe.de
  12. Mime-Version: 1.0
  13. Content-Type: text/plain; charset=iso-8859-1
  14. Content-Transfer-Encoding: 8bit
  15. In-reply-to: Webb Scales's message of Mon, 26 Feb 1996 14:16:21 -0500
  16. X-WWW-Home-Page: http://www.colibri.de/~hf/
  17. X-PGP-Public-Key: finger hf@colibri.de
  18. X-PGP-Fingerprint: 09 4E C4 A2 B2 C5 33 1A  79 80 5D 39 BD 9B 89 39
  19. X-Disclaimer: Kore wa Colibri no iken dewa arimasen
  20. X-Newsreader: Gnus v5.0.9
  21.  
  22. Webb Scales <scales@zko.dec.com> writes:
  23.  
  24. > David Brownell wrote:
  25. >> One of the really nice techniques is to have a "Locker" class to grab mutexes
  26. >> as needed, and then release it automatically on all exits.  [...]
  27. >> That kind of class really helps get rid of the bugs you have due
  28. >> to locks not getting released uniformly on all codepaths.
  29.  
  30. > Hmmm...this approach makes me nervous.  I assert that it's better to
  31. > neglect to unlock a mutex than to unlock it when you shouldn't have.
  32.  
  33. Since the question was about pthreads in C++, you should use the
  34. technique presented nevertheless.  The problem is that you can leave
  35. the critical section not only in the "normal" way (where unlock() gets
  36. executed), but also by means of an exception thrown deep in your
  37. calling chain.  It's simply too easy to forget an appropriate catch clause.
  38.